<include file="Public/mobile_head"/>
<!--<script type="text/javascript" src="{:ADDON_PUBLIC_PATH}/mobile/shop.js?v={:SITE_VERSION}"></script>-->
<link href="{:ADDON_PUBLIC_PATH}/mobile/common.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
<link href="{:CUSTOM_TEMPLATE_PATH}Public/shop.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
<body>
<script type="text/javascript">
$(function(){
	//购物添加数量
	$('.buy_count .add').click(function(){
		var val = Number($(this).siblings('input').val());
		if(val<1){
			$(this).siblings('input').val(1);
		}else{
			$(this).siblings('input').val(val+1);
		}
		updatePriceAndCount();
	})
	$('.buy_count .reduce').click(function(){
		var val = Number($(this).siblings('input').val());
		if(val>1){
			$(this).siblings('input').val(val-1);
			updatePriceAndCount();
		}else{
			$(this).siblings('input').val(1);
			updatePriceAndCount();
		}
	})
	$('.buy_count input[type="text"]').keyup(function(){
		if($(this).val()==0){
			//$.Dialog.fail("购物数量不能小于1件");
			//$(this).val(1);
		}else{
			updatePriceAndCount();
		}
	})
	$('input[name="goods_ids[]"]').change(function(){
		updatePriceAndCount();
	})
	
	//全选的实现
	$(".check_all").click(function(){
		if($('input[name="checkAll"]').prop('checked')==true){
		$('input[name="goods_ids[]"]').prop('checked',true);
		
		}else{
			$('input[name="goods_ids[]"]').prop('checked',false);
		}
		updatePriceAndCount();
	});
	
})
//更新购物车价格和数量
function updatePriceAndCount(){
	var totalCount = 0;
	var totalPrice = 0;
	if($('input[name="goods_ids[]"]:checked').size()==$('input[name="goods_ids[]"]').size()){
		$('input[name="checkAll"]').prop('checked',true);
	}else{
		$('input[name="checkAll"]').prop('checked',false);
	}
	$('input[name="goods_ids[]"]:checked').each(function(index, element) {
		var itemElem = $(this).parents('li');
		var price = parseFloat(itemElem.find('.singlePrice').text());
		var count = parseInt(itemElem.find('input[rel="buyCount"]').val());
		totalCount += count;
		totalPrice += count*price
	});
	$('#totalCount').text(totalCount);
	$('#totalPrice').text(totalPrice);
}
//提交检查
function checkCartSubmit(){
	if($('input[name="goods_ids[]"]:checked').size()==0){
		$.Dialog.fail("请先选择要购买的商品");
		return false;
	}
}
function confirmGetGoods(url){
	$.Dialog.confirmBox('温馨提示','确认已收货？',{rightCallback:function(){
		$.Dialog.loading();
		$.post(url,function(res){
			 setTimeout(function(){
				 location.reload();	
			},1500);			
	    });
	}});
}

</script>
    <div class="container">
        <!-- 店标和名称 -->
        <div class="shop_row">
			<div class="shop_row_img">
				<img src="{:CUSTOM_TEMPLATE_PATH}Public/xintu5.jpg" />
				<div class="shop_row_title">
					{$page_title}
				</div>
				<a href="{:U('lists',array('shop_id'=>$shop_id))}" style="position:absolute;left:5px;top:50%;margin-top:-15px;color:#fff;font-size:30px;display:block;width:30px;height:30px;line-height:30px;">
					<img src="{:CUSTOM_TEMPLATE_PATH}Public/fanhui.png" style="width:100%;" />
				</a>
			</div>
        </div>
		
        	
        <!-- 详情信息 -->
        <form id="detailForm" action="{:addons_url('Shop://Wap/confirm_order')}" method="post">
        <input type="hidden" name="goods_id" value="{$goods.id}"/>
        <div class="detail_info">
        	<div class="info_item">
        		<h6 class="name">{$goods.title}</h6>
            	<p class="price">
                	￥<span id="price">{$goods.price|wp_money_format}</span>
                	
                </p>
            	<p class="beizhu">
					<span style="float:left;text-align:left;">
					截止时间：2016-06-20 00:00:00
					</span>
					<php>
					if($goods['price']<=1){
					</php>
						<span style="float:right;text-align:right;">
						已有 {$goods.sale_count}份爱心
						</span>
					<php>
					}else{
					</php>
						<span style="float:right;text-align:right;">
						限额 {$goods.inventory}份 | 剩余 {$goods.shengyu}份
						</span>
					<php>
					}
					</php>
					<div style="clear:both;"></div>
                </p>
            </div>
			<php>
			if($goods['price']<=1){
			</php>
				<div class="info_item">
					<p>爱心份数</p>
					<div class="buy_count">
						<a class="reduce" href="javascript:;">-</a>
						<input type="text" name="buyCount" value="1"/>
						<a class="add" href="javascript:;">+</a>
						
					</div>
				</div>
			<php>
			}else{
			</php>
				<input type="hidden" name="buyCount" readonly value="1"/>
			<php>
			}
			</php>
        </div>
        <!-- 众筹介绍 -->
        <div class="detail_content">
            <div class="content">
			{$goods.content}
            </div>
        </div>
        </form>
    </div>
        <!-- 分类目录 -->
    
    <!-- 底部加入购物车等 -->
	<div class="bottom_menus"> 
		<a class="home" href="{:U('index', array('shop_id'=>$shop_id))}"></a> 
		<php>
		if($goods['shengyu']<1){
		</php>
			<a class="zcbtn" href="javascript:;" style="background:#ccc;">确认支持</a> 
		<php>
		}else{
		</php>
			<a class="zcbtn" href="javascript:;" onClick="buyNow()">确认支持</a> 
		<php>
		}
		</php>
		
		<a class="center" href="{:U('user_center', array('shop_id'=>$shop_id))}"></a> 
	</div>
	<p class="copyright">{$system_copy_right}{$tongji_code}</p>
<script type="text/javascript">
//加入收藏
function addToFavorite(){
	$.Dialog.loading();
	var data = $('#detailForm').serializeArray();
	$.ajax({
		url:"{:U('addToCollect',array('shop_id'=>$shop_id))}",
		data:data,
		dataType:'JSON',
		type:"POST",
		success:function(data){
			if(data){
				$.Dialog.success("收藏成功");
			}
		}
	})
}
function addToCart(){
	
	if(Number($('input[name="buyCount"]').val())<1){
		$.Dialog.fail("购物数量不能小于1件");
		return;	
	}
//	if(!$('.sku_check:checked').val()){
//		$.Dialog.fail("请选择型号");
//		return;	
//	}
	$.Dialog.loading();
	var data = $('#detailForm').serializeArray();
	$.ajax({
		url:"{:U('addToCart',array('shop_id'=>$shop_id))}",
		data:data,
		dataType:'html',
		type:"POST",
		success:function(res){
			if(res){
				$.Dialog.success("加入购物车成功");
				$('#cartCount').text(res);
			}
		}
	})
}
function buyNow(){
	if(Number($('input[name="buyCount"]').val())<1){
		$.Dialog.fail("购物数量不能小于1件");
		return;	
	}
//	if(!$('.sku_check:checked').val()){
//		$.Dialog.fail("请选择型号");
//		return;	
//	}
	$('#detailForm').submit();
}
$(function(){
	$.WeiPHP.gallery('.photoList','.photoList ul');
	$('.sku_item').click(function(){
		$('#price').text($(this).data('price'));
		$(this).addClass('select').siblings().removeClass('select');
		$(this).find('input').prop("checked",true);
		$(this).siblings().find('input').prop("checked",false);
	})
	//图片预览
	var picList = [];
	$('.photoList li img').each(function(index, element) {
		var picUrl = $(this).attr("src");
		picList[index] = picUrl;
        $(this).click(function(){
			wx.previewImage({
				current: picUrl, // 当前显示的图片链接
				urls: picList // 需要预览的图片链接列表
			});
		})
    });
	
		//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search_form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});	
});

</script>	

</body>
</html>